﻿using Cart.SanPhamSrv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class PopupChiTiet : VdcInc.vdcAJAXPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            long idsanpham = (IsNumeric(Request.QueryString["masanpham"]) == false ? 0 : Convert.ToInt64(Request.QueryString["masanpham"]));
            if (idsanpham == 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "window.close();", true);
            }
            else
            {
                Session["IdSanPham"] = idsanpham;
                using (var userService = new SanPhamSrv.SanPhamServiceClient())
                {
                    var modelsanpham = userService.ChiTietSanPham(idsanpham);
                    lbLoai.InnerText = modelsanpham.Ten.ToUpper();
                    lvDsAnh.DataSource = modelsanpham.lstAnh;
                    lvDsAnh.DataBind();

                    lvNoiDungCT.DataSource = modelsanpham.lstNoiDung;
                    lvNoiDungCT.DataBind();
                }
            }
        }
        public string vXoaChiTiet(string strChiTietId, string strLoai)
        {
            using (var spService = new SanPhamSrv.SanPhamServiceClient())
            {
                string result = "";
                if (strLoai == "1")
                {
                    var anhct = new SanPhamAnhCT();
                    
                    anhct.IdChiTiet = Convert.ToInt64(strChiTietId);
                    result = spService.CapNhatSanPhamChiTiet(anhct,null);
                }
                else {
                    var ndct = new SanPhamNoiDungCT();
                    ndct.IdChiTiet = Convert.ToInt64(strChiTietId);
                    result = spService.CapNhatSanPhamChiTiet(null,ndct);
                }
                
                return "Xóa " + result;
            }
        }
        public static bool IsNumeric(string text)
        {
            return string.IsNullOrEmpty(text) ? false :
                    Regex.IsMatch(text, @"^\s*\-?\d+(\.\d+)?\s*$");
        }
    }
}